// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,
	
    properties: {
        scoreDisplay: {
            default: null,
            type: cc.Label
        },
		historyDisplay: {
            default: null,
            type: cc.Label
        },
		stepDisplay: {
            default: null,
            type: cc.Label
        },
		game: {
            default: null,
            type: cc.Node
        },
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
		this.score = 0;
		this.history=0;
		this.step=0;
	},

    update (dt) {
		if(this.game.getComponent('GameByTime').getScore()!=this.score){
			//console.log('change score');
			this.score = this.game.getComponent('GameByTime').getScore();
			this.scoreDisplay.string = '得分:'+this.score;
		}
		
		if(this.game.getComponent('GameByTime').getTarget()!=this.history){
			//console.log('change score');
			this.history = this.game.getComponent('GameByTime').getTarget();
			this.historyDisplay.string = '最高分:'+this.history;
		}
		
		
		if(this.game.getComponent('GameByTime').getStep()!=this.step){
			//console.log('change step');
			this.step = this.game.getComponent('GameByTime').getStep();
			
			if(this.step<=0){
				this.stepDisplay.string = '时间:0.00';
			}else{
				var nmb = this.step%100;
				var nmbstr = nmb<10?'0'+nmb:nmb;
				this.stepDisplay.string = '时间:'+(this.step-nmb)/100+"."+nmbstr;
			}
		} 
	},
});
